var e = require("../../utils/util.js"), t = getApp();

Page({
    data: {
        show1: !0,
        show2: !1,
        cueTime: "",
        cueTimeNum: "0000",
        year: 0,
        timeStr: "",
        time: new Date(),
        minuteNum: "0000",
        dayTime: "",
        detailTime: "",
        dataType: "0"
    },
    onLoad: function(a) {
        var i = this, r = new Date(), l = (e.formatDate1(r), i.getNowTime()), o = i.getDateStr(l, 1), s = i.getDateStr(l, 2);
        i.setData({
            beginTime: t.globalData.serBegintime,
            endTime: t.globalData.serEndtime,
            minuteNum2: t.globalData.serEndtime.replace(":", ""),
            Today: l.split(" ")[0].split("-")[1] + "月" + l.split(" ")[0].split("-")[2] + "日",
            tomorrow: o.split(" ")[0].split("-")[1] + "月" + o.split(" ")[0].split("-")[2] + "日",
            afterTomorrow: s.split(" ")[0].split("-")[1] + "月" + s.split(" ")[0].split("-")[2] + "日",
            dayTime: l
        }), t.globalData.serDetail.orderTime = l + " " + i.detailTime + ":00";
        var m = t.globalData.urlBase + t.globalData.urlStoreYuYueTime;
        i.getTimeData(m, l);
    },
    getTimeData: function(e, a) {
        var i = this, r = JSON.stringify(t.globalData.cartList);
        console.log(r), wx.request({
            url: e,
            data: {
                lng: t.globalData.lng,
                lat: t.globalData.lat,
                storeId: t.globalData.storeId,
                serverId: t.globalData.serverId,
                dayTime: a,
                gListStr: r
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(e) {
                var t = JSON.parse(e.data);
                if (0 != t.code) wx.showToast({
                    title: t.msg,
                    icon: "none",
                    duration: 2e3
                }); else {
                    for (var a = [], r = [], l = 0; l < t.list1.length; l++) (o = {}).time = t.list1[l].time, 
                    o.timeInt = t.list1[l].time.replace(":", ""), o.state = t.list1[l].state, a.push(o);
                    for (l = 0; l < t.list2.length; l++) {
                        var o = {};
                        o.time = t.list2[l].time, o.timeInt = t.list2[l].time.replace(":", ""), o.state = t.list2[l].state, 
                        r.push(o);
                    }
                    i.setData({
                        list1: a,
                        list2: r
                    });
                }
            }
        });
    },
    onShow: function() {
        var a = this, i = t.globalData.yuyueTime, r = a.data.beginTime.replace(":", "");
        if (i.length > 0) {
            var l = new Date(), o = e.formatDate(l), s = e.formatNumber(l.getHours()) + "" + e.formatNumber(l.getMinutes());
            console.log(i);
            var m = i.split(" ")[1], u = e.formatNumber(m.split(":")[0]) + e.formatNumber(m.split(":")[1]);
            console.log(i.split(" ")[0].split("-")[1] + "月" + i.split(" ")[0].split("-")[2] + "日"), 
            a.setData({
                year: i.split(" ")[0].split("-")[0],
                timeStr: i.split(" ")[0].split("-")[1] + "月" + i.split(" ")[0].split("-")[2] + "日",
                time: new Date(i),
                minuteNum: o.replace("月", "").replace("日", "") == i.split(" ")[0].split("-")[1] + i.split(" ")[0].split("-")[2] ? s : "0000",
                show1: 1730 >= u,
                show2: 1730 < u,
                todayNum: o.replace("月", "").replace("日", ""),
                cueTimeNum: u,
                cueTime: i,
                dayTime: i
            });
        } else {
            var n = new Date(), i = e.formatDate(n), s = e.formatNumber(n.getHours()) + "" + e.formatNumber(n.getMinutes());
            a.setData({
                year: n.getFullYear(),
                timeStr: i,
                time: new Date(),
                minuteNum: s < r ? r : s,
                show1: 1730 > s,
                show2: 1730 <= s,
                todayNum: i.replace("月", "").replace("日", ""),
                dayTime: n.getFullYear() + "-" + i.replace("月", "-").replace("日", "-")
            });
        }
    },
    changeShow1: function() {
        this.setData({
            show1: !0,
            show2: !1
        });
    },
    changeShow2: function() {
        this.setData({
            show1: !1,
            show2: !0
        });
    },
    addDay: function(a) {
        var i = new Date(), r = this, l = Date.parse(r.data.time), o = 1e3 * ((l /= 1e3) + 86400), s = new Date(o), m = e.formatDate(s);
        r.setData({
            time: s,
            timeStr: m,
            minuteNum: "0000",
            dayTime: i.getFullYear() + "-" + m.replace("月", "-").replace("日", ""),
            dataType: a.currentTarget.dataset.type
        });
        var u = r.getNowTime(), n = r.getDateStr(u, 1), g = r.getDateStr(u, 2), D = t.globalData.urlBase + t.globalData.urlStoreYuYueTime;
        1 == a.currentTarget.dataset.type ? (r.getTimeData(D, n), t.globalData.yuyueTime = n + " " + r.data.detailTime + ":00", 
        t.globalData.serDetail.orderTime = n + " " + r.data.detailTime + ":00") : (r.getTimeData(D, g), 
        t.globalData.serDetail.orderTime = g + " " + r.data.detailTime + ":00", t.globalData.yuyueTime = g + " " + r.data.detailTime + ":00");
    },
    mulDay: function(a) {
        var i = this, r = Date.parse(i.data.time), l = 1e3 * ((r /= 1e3) - 86400), o = new Date(l), s = e.formatDate(o), m = new Date(), u = i.getNowTime(), n = e.formatNumber(m.getHours()) + "" + e.formatNumber(m.getMinutes());
        i.setData({
            time: o,
            timeStr: s,
            minuteNum: n < i.data.begintime ? i.data.begintime : n,
            dayTime: m.getFullYear() + "-" + s.replace("月", "-").replace("日", ""),
            dataType: a.currentTarget.dataset.type
        }), t.globalData.serDetail.orderTime = u + " " + i.data.detailTime + ":00";
        var g = t.globalData.urlBase + t.globalData.urlStoreYuYueTime;
        i.getTimeData(g, u);
    },
    chooseTime: function(e) {
        var a = this, i = e.currentTarget.dataset.num;
        if (!(a.data.minuteNum >= i.replace(":", "")) && a.data.cueTimeNum != i.replace(":", "")) {
            var r = a.data.year + "-" + a.data.timeStr + " " + i + ":00";
            r = r.replace("月", "-").replace("日", ""), a.setData({
                detailTime: i,
                cueTimeNum: i.replace(":", ""),
                cueTime: r
            }), t.globalData.yuyueTime = r, t.globalData.serDetail.orderTime = a.getNowTime() + " " + a.data.detailTime + ":00";
        }
    },
    sub: function() {
        var e = this;
        t.globalData.cartList.length <= 0 ? wx.navigateTo({
            url: "../cproject/cproject"
        }) : e.data.cueTime.length <= 0 ? wx.showToast({
            title: "请选择时间",
            icon: "none",
            duration: 2e3
        }) : wx.navigateTo({
            url: "../reserInfo/reserInfo"
        });
    },
    getNowTime: function() {
        var e = new Date(), t = e.getFullYear(), a = e.getMonth() + 1, i = e.getDate();
        return a < 10 && (a = "0" + a), i < 10 && (i = "0" + i), t + "-" + a + "-" + i;
    },
    getDateStr: function(e, t) {
        var a;
        (a = e ? new Date(e) : new Date()).setDate(a.getDate() + t);
        var i = a.getFullYear(), r = a.getMonth() + 1, l = a.getDate();
        return r < 10 && (r = "0" + r), l < 10 && (l = "0" + l), i + "-" + r + "-" + l;
    },
    onShareAppMessage: function() {}
});